package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.common.ErrorType;
import com.engineering.elink.service.CourseTypeService;
import com.engineering.elink.util.ResJsonUtil;

/**
 * 课程分类管理restful接口，支持跨域
 */
@RestController
@CrossOrigin
@RequestMapping("/api/coursetype")
@Api(value="课程分类管理接口")
public class CourseTypeController {

	@Autowired
	private CourseTypeService courseTypeService;
	
	/**
	 * 获取课程分类
	 */
	@RequestMapping(value = "/getCourseType", method = RequestMethod.GET)
	@ApiOperation(value = "获取课程分类")
	public Map<String, Object> getCourseType() {
		return ResJsonUtil.getMap(ErrorType.SUCCESS,courseTypeService.getCourseType());
	}
	
	/**
	 * 删除单个课程分类
	 */
	@RequestMapping(value="/deleteCourseType",method=RequestMethod.DELETE)
	@ApiOperation(value="删除单个课程分类")
	public Map<String,Object> deleteCourseType(@ApiParam(value="分类id",required=true) @RequestParam(value = "typeId",required=true)Integer typeId){
		
		return courseTypeService.deleteCourseType(typeId);
		
	}
	
	/**
	 * 批量保存更新课程分类
	 */
	@RequestMapping(value="/updateCourseType",method=RequestMethod.POST)
	@ApiOperation(value="批量保存更新课程分类")
	public Map<String,Object> updateCourseType(
			@ApiParam(value="分类JSON字符串(示例:[{\"id\":0,\"name\":\"a\"},{\"id\":0,\"name\":\"b\"}],0表示为新增的否则修改有ID值)",required=true) @RequestParam(value="jsonStr",required=true) String jsonStr){
		return courseTypeService.updateCourseType(jsonStr);
	}
	
}
